<template>
  <a-layout-header :class="[headerTheme, 'admin-header']">
    <div :class="['admin-header-wide', layout, pageWidth]">
      <router-link
        v-if="isMobile || layout === 'head'"
        to="/"
        :class="['logo', isMobile ? null : 'pc', headerTheme]"
      >
        <img width="32" :src="logo" />
        <h1 v-if="!isMobile">{{ websiteName }}</h1>
      </router-link>
      <a-divider v-if="isMobile" type="vertical" />
      <a-icon
        v-if="layout !== 'head'"
        class="trigger"
        :type="collapsed ? 'menu-unfold' : 'menu-fold'"
        @click="toggleCollapse"
      />
      <div
        v-if="layout !== 'side' && !isMobile"
        class="admin-header-menu"
        :style="`width: ${menuWidth};`"
      >
        <i-menu
          class="head-menu"
          :theme="headerTheme"
          mode="horizontal"
          :menu="menuData"
          @select="onSelect"
        />
      </div>
      <div :class="['admin-header-right', headerTheme]">
        <!-- <header-search class="header-item" @active="val => searchActive = val" /> -->
        <header-screenfull class="header-item" />
        <!-- <header-notice class="header-item" /> -->
        <!-- <a-tooltip class="header-item" title="gitHub" placement="bottom" >
            <a href="https://jq.qq.com/?_wv=1027&k=ITuTKtdx" target="_blank">
              <a-icon type="qq" />
            </a>
          </a-tooltip>

          <a-tooltip class="header-item" title="gitHub" placement="bottom" >
            <a href="https://github.com/duzhenyi/duling-vue" target="_blank">
              <a-icon type="github" />
            </a>
          </a-tooltip> -->

        <header-avatar
          class="header-item"
          @handleShowUpdatePwd="handleShowUpdatePwd"
        />
        <!-- <a-dropdown class="lang header-item">
            <div>
              <a-icon type="global"/> {{langAlias}}
            </div>
            <a-menu @click="val => setLang(val.key)" :selected-keys="[lang]" slot="overlay">
              <a-menu-item v-for=" lang in langList" :key="lang.key">{{lang.key.toLowerCase() + ' ' + lang.name}}</a-menu-item>
            </a-menu>
          </a-dropdown> -->
      </div>
    </div>

    <update-pwd
      :updatePwdVisible="updatePwdVisible"
      @handleHideUpdatePwd="handleHideUpdatePwd"
    />
  </a-layout-header>
</template>

<script>
import updatePwd from "./updatePwd";
import HeaderScreenfull from "./HeaderScreenfull";
import HeaderSearch from "./HeaderSearch";
import HeaderNotice from "./HeaderNotice";
import HeaderAvatar from "./HeaderAvatar";
import IMenu from "@/components/menu/menu";
import { mapGetters,mapState, mapMutations } from "vuex";

export default {
  name: "AdminHeader",
  components: {
    IMenu,
    HeaderAvatar,
    HeaderNotice,
    HeaderSearch,
    HeaderScreenfull,
    updatePwd,
  },
  props: ["collapsed", "menuData"],
  data() {
    return {
      updatePwdVisible: false,
      // langList: [
      //   { key: "CN", name: "简体中文", alias: "简体" },
      //   { key: "HK", name: "繁體中文", alias: "繁體" },
      //   { key: "US", name: "English", alias: "English" },
      // ],
      searchActive: false,
    };
  },
  computed: {
    // ...mapState("website", ["websiteName", "logo"]),
     ...mapGetters(["websiteName",'logo']),
    ...mapState("setting", [
      "theme",
      "isMobile",
      "layout",
      "lang",
      "pageWidth",
    ]),
    headerTheme() {
      if (
        this.layout == "side" &&
        this.theme.mode == "dark" &&
        !this.isMobile
      ) {
        return "light";
      }
      return this.theme.mode;
    },
    // langAlias() {
    //   let lang = this.langList.find((item) => item.key == this.lang);
    //   return lang.alias;
    // },
    menuWidth() {
      const { layout, searchActive } = this;
      const headWidth = layout === "head" ? "100% - 188px" : "100%";
      const extraWidth = searchActive ? "600px" : "400px";
      return `calc(${headWidth} - ${extraWidth})`;
    },
  },
  methods: {
    handleShowUpdatePwd() {
      this.updatePwdVisible = true;
    },
    handleHideUpdatePwd() {
      this.updatePwdVisible = false;
    },
    toggleCollapse() {
      this.$emit("toggleCollapse");
    },
    onSelect(obj) {
      this.$emit("menuSelect", obj);
    },
    ...mapMutations("setting", ["setLang"]),
  },
};
</script>

<style lang="less" scoped>
@import "index";
</style>
